package com.sgcc.ln.pmos.e_ln_personalcenter.presenter;

import com.sgcc.ln.pmos.common.base.BasePresenter;
import com.sgcc.ln.pmos.common.bean.BaseResponse;
import com.sgcc.ln.pmos.common.http.HttpInterConst;
import com.sgcc.ln.pmos.common.http.HttpRequestUtils;
import com.sgcc.ln.pmos.common.http.MvpNetCallback;
import com.sgcc.ln.pmos.e_ln_personalcenter.bean.PowerCurveBean;
import com.sgcc.ln.pmos.e_ln_personalcenter.contract.DeviationCurveContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;


public class DeviationCurvePresenter extends BasePresenter<DeviationCurveContract.View> implements DeviationCurveContract.Presenter {

    @Override
    public void queryCurveInfo() {
        Map<String, Object> params = new HashMap<>();
        params.put("_t", System.currentTimeMillis());
        params.put("ratioId", "");
        params.put("eSource", "4");
        HttpRequestUtils.getInstance().request(params, HttpInterConst.USER_QUERYCURVEINFO, new MvpNetCallback<PowerCurveBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
            }

            @Override
            public void onResponse(PowerCurveBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().queryCurveInfoSuccess(response);
            }
        });
    }

    @Override
    public void deleteCurveInfo(String ratioId) {
        Map<String, Object> params = new HashMap<>();
        params.put("_t", System.currentTimeMillis());
        params.put("ratioId", ratioId);
        HttpRequestUtils.getInstance().request(params, HttpInterConst.USER_DELETECURVEINFO, new MvpNetCallback<BaseResponse>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                // 失败回调 判断界面是否销毁
                if (!isViewAttached()) {
                    return;
                }
            }

            @Override
            public void onResponse(BaseResponse response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().deleteCurveInfoSuccess(response);
            }
        });
    }
}
